﻿using UnityEngine;
using System.Collections;
using BehaviorDesigner.Runtime;

/// <summary>
/// 用于行为树使用的对象
/// </summary>
public class btBufferShared : MonoBehaviour
{
    public btBufferCfg _btBufferCfg;

    #region 设定行为树
    public BehaviorDesigner.Runtime.BehaviorTree _BehaviorTree;

    public void Serialize(btBufferCfg cfg)
    {
        _btBufferCfg = cfg;
        for (int i = 0; i < _btBufferCfg.ArrayName.Length; ++i)
        {
            SetValue(_btBufferCfg.ArrayName[i], _btBufferCfg.ArrayType[i], _btBufferCfg.ArrayValue[i]);
        }
    }

    /// <summary>
    /// 设置类型对应的值
    /// </summary>
    /// <param name="name"></param>
    /// <param name="type"></param>
    /// <param name="value"></param>
    public void SetValue(string name, string type, string value)
    {
        if (type == "SharedString")
        {
            SharedString s = new SharedString();
            s.Value = value;

            _BehaviorTree.SetVariable(name, s);
        }
        //else if (type == "SharedGameObject")
        //{
        //    SharedGameObject s = new SharedGameObject();
        //    s.Value = (GameObject)GameObject.Instantiate(Resources.Load("Battle/Character/luoxinfu_debuff"));

        //    _BehaviorTree.SetVariable(name, s);
        //}
        else if (type == "SharedFloat")
        {
            SharedFloat s = new SharedFloat();
            s.Value = float.Parse(value);

            _BehaviorTree.SetVariable(name, s);
        }
        else if (type == "SharedVector3")
        {
            SharedVector3 s = new SharedVector3();
            s.Value = Vector3.zero;

            _BehaviorTree.SetVariable(name, s);
        }
    }
    #endregion
}
